package adminClient;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

import common.AdministratorService;
import common.Tools;

public class AdminClientTest {

	public static void main(String[] args) {
		try {
			String adminIPAddressEU = Tools.getproperty("client.properties",
					"adminIPAddressEU");
			String adminIPAddressNA = Tools.getproperty("client.properties",
					"adminIPAddressNA");
			String adminIPAddressAS = Tools.getproperty("client.properties",
					"adminIPAddressAS");
			
			String hostEU = Tools.getproperty("client.properties", "serverName_EU");
			String hostNA = Tools.getproperty("client.properties", "serverName_NA");
			String hostAS = Tools.getproperty("client.properties", "serverName_AS");
			
			int RMIPortEU = Integer.parseInt(Tools.getproperty(
					"client.properties", "RMIPortEU"));
			int RMIPortNA = Integer.parseInt(Tools.getproperty(
					"client.properties", "RMIPortNA"));
			int RMIPortAS = Integer.parseInt(Tools.getproperty(
					"client.properties", "RMIPortAS"));

			Registry registryEU = LocateRegistry.getRegistry(hostEU, RMIPortEU);
			Registry registryNA = LocateRegistry.getRegistry(hostNA, RMIPortNA);
			Registry registryAS = LocateRegistry.getRegistry(hostAS, RMIPortAS);

			AdministratorService administratorServiceEU = (AdministratorService) registryEU
					.lookup(Tools.getproperty("client.properties", "adminEU"));
			AdministratorService administratorServiceNA = (AdministratorService) registryNA
					.lookup(Tools.getproperty("client.properties", "adminNA"));
			AdministratorService administratorServiceAS = (AdministratorService) registryAS
					.lookup(Tools.getproperty("client.properties", "adminAS"));
			
			AdminClient adminClientEU = new AdminClient(administratorServiceEU);
			AdminClient adminClientNA = new AdminClient(administratorServiceNA);
			AdminClient adminClientAS = new AdminClient(administratorServiceAS);

			new Thread(new AdminClientThread(adminClientEU, "Admin", "Admin", adminIPAddressEU)).start();
			new Thread(new AdminClientThread(adminClientNA, "Admin", "Admin", adminIPAddressNA)).start();
			new Thread(new AdminClientThread(adminClientAS, "Admin", "Admin", adminIPAddressAS)).start();
			
			/*new Thread(new AdminClientThread(adminClientEU, "Admin", "Admin1", adminIPAddressEU)).start();
			new Thread(new AdminClientThread(adminClientNA, "Admin", "Admin1", adminIPAddressNA)).start();
			new Thread(new AdminClientThread(adminClientAS, "Admin", "Admin1", adminIPAddressAS)).start();*/

		} catch (RemoteException e) {
			Tools.writeLog("client", "client", "admin client RMI failed:"
					+ e.detail.getMessage(), false);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
